<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<html>
<head>
    <title>技术论坛系统</title>
    <link href="/css/bootstrap.css" rel="stylesheet">
    <link href="/css/style.css" rel="stylesheet">

</head>
<body style="background-color: #fafafa">
<script type="text/javascript" src="/js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/js/bootstrap.js"></script>
<div class="container-fluid">
    <img src="/img/navback.jpg" alt="..." class="note-img">
    <div class="row">
        <div class="col-md-3">
            <ul class="list-group">
                <li class="list-group-item"><a href="${pageContext.request.contextPath}/api/admin/">分类管理</a></li>
                <li class="list-group-item"><a href="${pageContext.request.contextPath}/api/admin/manageNote">帖子管理</a>
                </li>
            </ul>

        </div>

        <div class="col-md-9" style="background-color: white;">
            <table class="table table-hover">
                <tr class="manage-item">
                    <th>id</th>
                    <th>内容</th>
                    <th>作者</th>
                    <th>操作</th>
                </tr>
                <c:forEach items="${comments}" var="comment">
                    <tr>
                        <td>${comment.notecommentid}</td>
                        <td><textarea class="form-control" rows="4"
                                      id="text${comment.notecommentid}">${comment.commenttext}</textarea></td>
                        <td>${comment.createby}</td>
                        <td>
                            <button type="button" class="btn btn-default" onclick="changeupdate(${comment.notecommentid})">修改</button>
                            <button type="button" class="btn btn-default" onclick="deleteupdate(${comment.notecommentid})">删除</button>
                        </td>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>
</div>
<script type="text/javascript">
    function changeupdate(notecommentid) {
        var text = $("#text" + notecommentid).val()
        $.post("${pageContext.request.contextPath}/api/admin/comment/edit", {
            "commentId": notecommentid,
            "text": text
        }, function (data) {
            if (data.success == 1) {
                alert("修改成功！");
                window.location.reload();
            } else {
                alert("修改失败！");
            }
        })
    }

    function deleteupdate(notecommentid) {
        $.post("${pageContext.request.contextPath}/api/admin/comment/delete", {
            "commentId": notecommentid
        }, function (data) {
            if (data.success == 1) {
                alert("修改成功！");
                window.location.reload();
            } else {
                alert("修改失败！");
            }
        })
    }
</script>
</body>
</html>
